package com.mstore.dao;

import java.util.List;

import com.mstore.pojo.OrderInfo;

public class OrderInfoDao extends SuperDao {

	/**
	 * 查询企业的订单
	 */
	public List<Object> watchMyOrderInfo(Long eaId) {
		/*String hql = "from OrderInfo where account.id = " + eaId;
		return super.find(hql);*/
		
		StringBuilder sb=new StringBuilder();
		sb.append("from OrderInfo where account.id = ");
		sb.append(eaId);
		return super.find(sb.toString());
	}

	/**
	 * 企业下订单
	 */
	public void addMyOrderInfo(OrderInfo orderInfo) {
		super.save(orderInfo);
	}
	
	/**
	 * 查询企业的订单
	 */
	public List<Object> finadMyOrderInfoByOrderId(String orderId) {
		/*String hql = "from OrderInfo where orderId = '" + orderId + "'";
		return super.find(hql);*/
		
		StringBuilder sb = new StringBuilder();
		sb.append("from OrderInfo where orderId = '");
		sb.append(orderId);
		sb.append("'");
		return super.find(sb.toString());
	}
	
	/**
	 * 更新企业订单
	 */
	public void updateMyOrderInfo(OrderInfo orderInfo) {
		super.update(orderInfo);
	}
	
	/**
	 * 根据企业id和资费表id查询订单
	 * 返回最新的“已支付”状态的订单
	 */
	public Object findMyOrderInfoByEaIdAndTariffId(Long eaId, Long tariffId) {
		String sql = "from OrderInfo where ea_id = ? and tariff_id = ? and status = 1 order by createDate desc";
		List<Object> list = super.getObject(sql, new Object[] { eaId, tariffId });
		if (list.isEmpty()) {
			return null;
		}
		return list.get(0);
	}
	
	/**
	 * 删除订单
	 * * @param orderInfo
	 */
	public void delOrderInfo(OrderInfo orderInfo) {
		super.delete(orderInfo);
	}
	
}
